import { applyDecorators, Type } from '@nestjs/common';
import { ApiOkResponse, getSchemaPath } from '@nestjs/swagger';
import { Pagination } from 'src/logical/common/models/Pagination.model';
// import { ResponseObjDto } from '../logical/content/dto/content.dto'

export const ApiObjResponse = <TModel extends Type<any>>(model: TModel) => {
  return applyDecorators(
    ApiOkResponse({
      schema: {
        title: '响应示例',
        allOf: [
          {
            properties: {
              data: { $ref: getSchemaPath(model) },
              code: { type: 'number', default: '200' },
              msg: { type: 'string', default: 'success' },
            },
          },
        ],
      },
    }),
  );
};
export const ApiCommonResponse = () => {
  return applyDecorators(
    ApiOkResponse({
      schema: {
        title: '响应示例',
        allOf: [
          {
            properties: {
              data: {
                type: 'string',
                default: '',
              },
              code: { type: 'number', default: '200' },
              msg: { type: 'string', default: 'success' },
            },
          },
        ],
      },
    }),
  );
};
export const ApiPaginatedResponse = <TModel extends Type<any>>(
  model: TModel,
) => {
  return applyDecorators(
    ApiOkResponse({
      schema: {
        title: '响应示例',
        allOf: [
          {
            properties: {
              datas: {
                type: 'array',
                items: { $ref: getSchemaPath(model) },
              },
              pagination: {
                type: 'object',
                allOf: [{ $ref: getSchemaPath(Pagination) }],
              },
              error_code: { type: 'number', default: '200' },
              error_msg: { type: 'string', default: 'success' },
            },
          },
        ],
      },
    }),
  );
};
